<extend name="Public/layout" />
<block name="pluginCSS">
<link href="__PUBLIC__/Home/plugins/uniform/css/uniform.default.css" rel="stylesheet" type="text/css"/>	
</block>
<block name="CSS">
	<style>#table_common .active{background:#f9f9f9}</style>
</block>
<block name="loadJS">
<script src="__PUBLIC__/Home/plugins/uniform/jquery.uniform.min.js" type="text/javascript" ></script>
</block>
<block name="initJS">
App.initUniform();
function changeCartGoodsnum(quantity,number){
	var params={};
	params.num = number;
	num=quantity.find('input').eq(0).val();
	params.goodsId=quantity.find('input').eq(1).val();
	params.goodsAttrId=quantity.find('input').eq(2).val();
	params.shopId=quantity.find('input').eq(3).val();
	params.shopPrice=quantity.find('input').eq(4).val();
	params.ischk=quantity.closest('tr').find('.checkboxes').val();
	$.post('<{:U('Cart/changeCartGoodsNum')}>',params,function(data){
		//alert(quantity.closest('tr').find('#goods_'+params.goodsId).html());
		quantity.closest('tr').find('#goods_'+params.goodsId).html('<span>&yen;</span>'+num*params.shopPrice);
		$('#sp2_'+params.shopId).html('<span>&yen;</span>'+data.shopTotalMoney);
		$('.totalMoney').html('<span>&yen;</span>'+data.totalMoney);
		$('.totalDeliveryMoney').html('<span>&yen;</span>'+data.totalDeliveryMoney);
		$('.totalMoneyAll').html('<span>&yen;</span>'+data.totalMoneyAll);
	});
}
$(".quantity-up,.quantity-down").click(function(){
	var quantity = $(this).closest('.product-quantity');
	var number = quantity.find('input').eq(0).val();
	changeCartGoodsnum(quantity,number);
	//alert(params);
})

jQuery('#table_common .group-checkable').change(function () {
    var set = jQuery(this).attr("data-set");
    var checked = jQuery(this).is(":checked");
    jQuery(set).each(function () {
        if (checked) {
            $(this).attr("checked", true);
            $(this).parents('tr').addClass("active");
        } else {
            $(this).attr("checked", false);
            $(this).parents('tr').removeClass("active");
        }                    
    });
    jQuery.uniform.update(set);
});

jQuery('#table_common').on('change', 'tbody tr .checkboxes', function(){
     $(this).parents('tr').toggleClass("active");
     var quantity = $(this).closest('tr').find('.product-quantity');
     if($(this).attr("checked")==true){
     	var number = quantity.find('input').eq(0).val();
     }else{
     	var number = 0;
     }
     changeCartGoodsnum(quantity,number);
});

</block>
<block name="breadcrumb"></block>
<block name="mainTop">
	
	<div class="row margin-bottom-40">
          <!-- BEGIN CONTENT -->
          <div class="col-md-12 col-sm-12">
            <h1>我的购物车</h1>
            <div class="shopping-cart-page">
              <div class="shopping-cart-data clearfix">
                <div class="table-wrapper-responsive">
                
                <table summary="Shopping cart" id="table_common">
                  <tr>
                  	<th>
					             <input type="checkbox" class="group-checkable" data-set="#table_common .checkboxes"/>
					           </th>
                    <th class="shopping-cart-image">图片</th>
                    <th class="shopping-cart-description">名称</th>
                    <th class="shopping-cart-ref-no">店铺</th>
                    <th>库存</th>
                    <th class="shopping-cart-quantity">数量</th>
                    <th class="shopping-cart-price">单价</th>
                    <th class="shopping-cart-total" colspan="2">金额</th>
                  </tr>
                  <foreach name="cartInfo['cartgoods']" item="shopgoods" key="key">
                  <tr>
                    <td colspan="9">
                      <strong><span id="sp_<{$shopgoods['shopgoods'][0]['shopId']}>"><i class="fa fa-truck"></i> <{$shopgoods["shopgoods"][0]["shopName"]}></span></strong>
					包邮起步价：&yen;<{$shopgoods["shopgoods"][0]["deliveryFreeMoney"]}>元
					           </td>
                  </tr>
                    <foreach name="shopgoods['shopgoods']" item="goods" >
                    <tr <if condition="$goods['ischk'] eq 1">class="active"</if>  id="sn<{$goods['goodsId']}>">
                    	<td>
                    	   <input type="checkbox" class="checkboxes" value="1" <if condition="$goods['ischk'] eq 1">checked</if>/>
                    	</td>
                    <td class="shopping-cart-image">
                      <a target="_blank" href="<{:U('Index/item',array('goodsId'=>$goods['goodsId']))}>" target="_blank"><img src="__UPLOAD__/<{$goods['goodsImg']?$goods['goodsImg']:$COMMON.goodsImage}>" width="60" />
		                  </a>
                    </td>
                    <td class="shopping-cart-description">                    
                      <h3><a href="<{:U('Index/item',array('goodsId'=>$goods['goodsId']))}>"><{$goods["goodsName"]}></a></h3>
                      <if condition="$goods['attrVal'] neq ''">
		                    <p><strong><{$goods['attrName']}></strong> - <{$goods['attrVal']}></p>
		                  </if>
                    </td>
                    <td class="shopping-cart-ref-no">
                      <a target="_blank" href="<{:U('',array('shopId'=>$goods['shopId']))}>" title="<{$goods['shopName']}>"><{$goods['shopName']}></a>
                    </td>
                    <td>
                    	<if condition="$goods['goodsStock'] egt $goods['cnt'] AND $goods['cnt'] gt 0 ">
	                                                                                                有货
	                        		<elseif condition="$goods['goodsStock'] eq 0"/>
	                                   	<span class="text-danger">无货</span>
	                           		<else/>
	                                    <span class="text-danger">库存不足,仅剩<{$goods["goodsStock"]}>份</span>
	                         		</if>                   	
                    </td>
                    <td class="shopping-cart-quantity">
                      <div class="product-quantity">
                          <input id="product-quantity" type="text" value="<{$goods["cnt"]}>" readonly class="form-control input-sm">                         
                          <input type="hidden" id="goodsId" value="<{$goods['goodsId']}>">
                         <input type="hidden" id="goodsAttrId" value="<{$goods['goodsAttrId']}>">
                         <input type="hidden" id="shopId" value="<{$goods['shopId']}>">
                         <input type="hidden" id="shopId" value="<{$goods['shopPrice']}>">
                      </div>
                    </td>
                    <td class="shopping-cart-price">
                      <strong><span>&yen;</span><{$goods["shopPrice"]}></strong>
                    </td>
                    <td class="shopping-cart-total" >
                      <strong id="goods_<{$goods["goodsId"]}>"><span>&yen;</span><{$goods["shopPrice"] * $goods["cnt"]}></strong>
                    </td>
                    <td class="del-goods-col">
                      <a  class="del-goods" href="javascript:delCartGoods(<{$goods['goodsId']}>,<{$goods['goodsAttrId']|default=0}>);">
                      <i class="fa fa-times"></i></a>
                    </td>
                  </tr>
                  </foreach>
                  <tr>
                  	<td colspan="9">
                  	<em>总计（不含运费）:</em>
                  	<strong class="price" id="sp2_<{$shopgoods['shopgoods'][0]['shopId']}>"><span>&yen;</span><{$shopgoods["totalMoney"]}></strong>
                  	</td>
                  </tr>
                  </foreach>
                </table>
                </div>

                <div class="shopping-total" style="width:250px">
                  <ul>
                    <li>
                      <em>应付总额(不含运费)：</em>
                      <strong class="price totalMoney"><span>&yen;</span><{$cartInfo['totalMoney']}></strong>
                    </li>
                    <li>
                      <em>运费</em>
                      <strong class="price totalDeliveryMoney"><span>&yen;</span><{$cartInfo['totalDeliveryMoney']}></strong>
                    </li>
                    <li class="shopping-total-price">
                      <em>应付总额</em>
                      <strong class="price totalMoneyAll"><span>&yen;</span><{$cartInfo['totalMoneyAll']}></strong>
                    </li>
                  </ul>
                </div>
              </div>
              <button class="btn btn-default" type="submit">继续购物 <i class="fa fa-shopping-cart"></i></button>
              <button class="btn btn-primary" type="submit">结算 <i class="fa fa-check"></i></button>
            </div>
          </div>
          <!-- END CONTENT -->
        </div>
</block>
<block name="side"></block>
<block name="page"></block>
<block name="mainBottom"></block>